#import "FlunetPlugin.h"
#if __has_include(<flunet/flunet-Swift.h>)
#import <flunet/flunet-Swift.h>
#else
// Support project import fallback if the generated compatibility header
// is not copied when this plugin is created as a library.
// https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816
#import "flunet-Swift.h"
#endif
#import "BLNetworkListener.h"

@interface FlunetPlugin()
@property(nonatomic, strong) BLNetworkListener *network;
@end
@implementation FlunetPlugin

+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
    ///建立通信通道 用来 监听Flutter 的调用和 调用Fluttter 方法 这里的名称要和Flutter 端保持一致
    FlutterMethodChannel *channel = [FlutterMethodChannel methodChannelWithName:@"flunet" binaryMessenger:registrar.messenger];
    
    FlunetPlugin *instance = [[FlunetPlugin alloc] initWithRegistrar:registrar methodChannel:channel];
    [registrar addMethodCallDelegate:instance channel:channel];
    [registrar addApplicationDelegate:instance];
    
    
//    [SwiftFlunetPlugin registerWithRegistrar:registrar];
}

- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
    if ([call.method isEqualToString:@"status"]) {
        [self.network fetchStatus:call result:result];
    }
    else {
        result(FlutterMethodNotImplemented);
    }
}

- (instancetype)initWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar methodChannel:(FlutterMethodChannel *)flutterMethodChannel {
    self = [super init];
    if (self) {
        self.network = [[BLNetworkListener alloc] initWithChannel:flutterMethodChannel];
    }

    return self;
}

#pragma mark -- Flutter 交互监听
-(void)onMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result{
    
}

@end
